package com.ljx.recruitment.interview.controller;

import com.ljx.recruitment.common.domain.vo.resp.ApiResult;
import com.ljx.recruitment.common.domain.vo.resp.PageResp;
import com.ljx.recruitment.interview.domain.entity.JobProcess;
import com.ljx.recruitment.interview.domain.vo.req.DeliverPageReq;
import com.ljx.recruitment.interview.domain.vo.req.DeliverProcessReq;
import com.ljx.recruitment.interview.domain.vo.req.DeliverSubmitReq;
import com.ljx.recruitment.interview.domain.vo.resp.DeliverResp;
import com.ljx.recruitment.interview.service.DeliverService;
import com.ljx.recruitment.security.common.PermissionConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ljx.recruitment.security.annotation.ApiPermission;

import java.util.List;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-11-02  00:06
 */
@Api(tags = "投递接口")
@RestController
@RequestMapping("/deliver")
public class DeliverController {

    @Autowired
    private DeliverService deliverService;

    @ApiOperation("获取用户投递")
    @GetMapping("/page")
    public ApiResult<PageResp<DeliverResp>> getPage(DeliverPageReq req){
        return ApiResult.success(deliverService.getPage(req));
    }

    @ApiPermission(permissions = {PermissionConstant.ADMIN_DELIVER_SUBMIT})
    @ApiOperation("投递状态变化")
    @PostMapping("/{deliverId}/nextStatus/{option}")
    public ApiResult<Void> changeStatus(@PathVariable("deliverId") Long deliverId, @PathVariable("option") Integer option,
                                        @RequestBody DeliverSubmitReq req){
        deliverService.changeStatus(deliverId, option, req);
        return ApiResult.success();
    }

    @ApiPermission(permissions = {PermissionConstant.USER_DELIVER})
    @ApiOperation("用户投递职位")
    @PostMapping("/submit")
    public ApiResult<DeliverResp> submit(@RequestBody DeliverSubmitReq req){
        return ApiResult.success(deliverService.submit(req));
    }

    @ApiOperation("检查职位是否投递")
    @PostMapping("/check/{jobId}")
    public ApiResult<Boolean> checkIsDeliver(@PathVariable("jobId") Long jobId){
        return ApiResult.success(deliverService.checkIsDeliver(jobId));
    }

    @ApiPermission(permissions = {PermissionConstant.ADMIN_DELIVER_SUBMIT})
    @ApiOperation("流程设置")
    @PostMapping("/process")
    public ApiResult<Void> processSubmit(@RequestBody DeliverProcessReq req){
        deliverService.processSubmit(req);
        return ApiResult.success();
    }


    @ApiPermission(permissions = {PermissionConstant.ADMIN_DELIVER_QUERY})
    @ApiOperation("获取该投递的可以设置的面试流程")
    @GetMapping("/process/{jobId}/tree")
    public ApiResult<List<JobProcess>> getDeliverProcessSettingList(@PathVariable("jobId") Long jobId,
                                                                    @RequestParam("deliverId") Long deliverId) {
        return ApiResult.success(deliverService.getDeliverProcessSettingList(jobId, deliverId));
    }

    @ApiOperation("查询员工内推的流程")
    @GetMapping("/recommend/page")
    public ApiResult<PageResp<DeliverResp>> getRecommendDeliverList(DeliverPageReq req) {
        return ApiResult.success(deliverService.getRecommendDeliverList(req));
    }


}
